﻿
namespace Service
{
    using Data.Repository;
	using System.Collections.Generic;

    public class AddressService : IAddressService
    {
        private IAddressRepository _addressRepository;

        #region IAddressService Members

        /// <summary>
        /// create new address method
        /// </summary>
        /// <param name="theNewAddress">the new address entity</param>
        /// <returns>the new address's ID</returns>
        public int CreateNewAddress(Data.Entity.Address theNewAddress)
        {
            if (theNewAddress == null)
            {
                return 0;
            }

            if (_addressRepository == null)
            {
                _addressRepository = new AddressRepository();
            }

            return _addressRepository.CreateNewAddress(theNewAddress);
        }

        public int DeleteAddress(int id)
        {
            if (id <= 0)
            {
                return 0;
            }

            if (_addressRepository == null)
            {
                _addressRepository = new AddressRepository();
            }

            return _addressRepository.DeleteAddress(id);
        }

        public int UpdateAddress(Data.Entity.Address theAddress)
        {
            if (theAddress == null || theAddress.UserID == null)
            {
                return 0;
            }

            if (_addressRepository == null)
            {
                _addressRepository = new AddressRepository();
            }

            return _addressRepository.UpdateAddress(theAddress);
        }

		public IList<Data.Entity.Address> GetTheUserAddresses(System.Guid userID)
		{
			if(userID == null)
			{
				return null;
			}

			if(_addressRepository == null)
			{
				_addressRepository = new AddressRepository();
			}

			return _addressRepository.GetTheUserAddresses(userID);
		}

		#endregion
	}
}
